<!-- 作者 : liandyao 公司: yidu -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登录注册</title>
    <link rel="shortcut icon" href="/res/images/my.ico">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="/res/css/style.css" />
    <script src="/res/js/jquery-3.4.1.min.js"></script>
    <script>
        $(function (){
            $("#btn_login").on("click",function (){
                //传过来的参数名一定要和对象中的属性名一模一样
                let data = {
                    usName:$("#userNameLogin").val(),
                    usPassword:$("#userPasswordLogin").val()
                }
                let url = "/flUser/findLogin";
                $.post(url,data,function (resp){
                    if(resp.state==1){
                        //将用户信息存入到session中
                        let user = JSON.stringify(resp.data);
                        sessionStorage.setItem("userInfo",user);
                        location.href="/index.html";
                    }else{
                        $(".verification").text("用户名或者密码错误!");
                    }
                },"json")
            })

            $("#registBtn").on("click",function (){

                let url = "/flUser/add";
                //将表单的字符串数据封装.不能用户上传文件
                let data = $("#registForm").serialize();
                console.info("表单数据",data);
                $.post(url,data,function(resp){
                    if(resp.state==1){
                        //跳到登录页面
                        $(".resetbtn").click();
                    }
                },"json");

            });
            //焦点离开
            $("#userName").on("blur",function (){
                let url = "/flUser/checkName";
                let data = {usName:$(this).val()}
                $.post(url,data,function (resp) {
                    if(resp.state==0){
                        $("#userName").val("");//不能注册
                        $(".verification").css("color","red");
                        $(".verification").html("用户名已存在!");
                    }else{
                        $(".verification").css("color","green");
                        $(".verification").html("恭喜该用户名可以注册!");
                    }
                },"json")
            })
        });
    </script>
    <style type="text/css">
        #sex input{
            width: 10%;
            height: 30%;
            margin-left: 20px;
        }
        #area select{
            width: 30%;
            height: 50%;
        }
        #hobby input{
            width: 10%;
            height: 30%;
            margin-left: 20px;
        }
        #photo input{
            width: 50%;
            height: 50%;
        }
        #remark textarea{
            width: 80%;
            height: 80%;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="main">
        <div class="bg"></div>
        <form class="formone" action="/" method="get">
            <div class="title">登 录</div>
            <div class="username"><input type="text"   id="userNameLogin"   value="" placeholder="请输入账号" /></div>
            <div class="password"><input type="password"  id="userPasswordLogin" value="" placeholder="请输入密码" /></div>
            <div class="verification"></div>
            <div class="loginbtn">
                <div class="btnbg"  id="btn_login">登录</div><button type="button">登录</button>
            </div>
            <div class="registerbtn">
                <div class="btnbg"  id="btn_regist">注册</div><button type="button">注册</button>
            </div>
        </form>
        <div class="registerpage">
            <form class="formtwo" action="/" method="" id="registForm">
                <div class="registertitle">注册</div>
                <div class="savename"><input type="text" name="usName" id="userName" value="" placeholder="请输入账号"/></div>
                <div class="savepassword"><input type="password" name="usPassword" id="userPwd" value="" placeholder="请输入密码"/></div>
                <div><input type="date" name="usBirthday"></div>
                <div class="verification"></div>
                <div class="btn_list">
                    <div class="okbtn" id="registBtn"><button type="button">确认</button></div>
                    <div class="resetbtn"><button type="button">撤销</button></div>
                </div>
            </form>

        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    let formone=document.querySelector('.formone');
    let registerpage=document.querySelector('.registerpage');
    let registerbtn=document.querySelector('.registerbtn');
    let resetbtn=document.querySelector('.resetbtn');
    registerbtn.addEventListener("click",()=>{
        formone.style.display='none';
        registerpage.style.display="flex";
    })
    resetbtn.addEventListener("click",()=>{
        formone.style.display='flex';
        registerpage.style.display="none";
    })
</script>
</html>